package com.programmercarl.dp;

/**
 * https://leetcode.cn/problems/integer-break/
 * 整数拆分 参考
 *
 * @author yulongtian
 * @create 2025-02-11 23:10
 */
public class Test06 {
    public static void main(String[] args) {

    }

    public int integerBreak(int n) {
        if (n <= 2) {
            return 1;
        }
        int[] dp = new int[n + 1];
        dp[2] = 1;
        for (int i = 3; i <= n; i++) {
            for (int j = 1; j <= i / 2; j++) {
                dp[i] = Math.max(dp[i], Math.max(dp[i - j] * j, (i - j) * j));
            }
        }
        return dp[n];
    }

}
